/**
 * @author TrinhNX
 * @start_date	: Jul 1, 2015
 * @end_date 	:
 */
public class Samsung {

	private static final int[][] DATA = {
			{ 1, 2, 3, 4 },
			{ 11, 12, 13, 5 },
			{ 16, 15, 14, 6 },
			{ 10, 9, 8, 7 } };

	private static final int DATA_SIZE = 4; // 4X4
	private static final int SUB_SIZE = 3; // 4X4

	public static void main(String[] args) {
		// For debug
		//		System.out.println("Sum : " + getSum(DATA, 1, 3, 1, 3));
		//		System.out.println("middle: " + getMiddle(DATA, 0, 2, 1, 3) + "\t" + DATA[2][1]);
		// Data array -> Get the pair x, y that 
		// has the sub_size inside the data_size
		// is pair inside {0, DATA_SIZE - SUB_SIZE}
		int sum = 0;
		for (int i = 0; i <= DATA_SIZE - SUB_SIZE; i++) {
			for (int j = 0; j <= DATA_SIZE - SUB_SIZE; j++) {
				System.out.println("i :" + i + "\t: j: " + j);
				// By adding the SUB_SIZE to fetch the index
				// -1 for index :D
				int temp_sum = getSum(DATA, i, i + SUB_SIZE - 1, j, j
						+ SUB_SIZE - 1);
				sum = temp_sum > sum ? temp_sum : sum;
			}
		}
		System.out.println(sum);
	}

	// Get the sum value of data array 
	private static int getSum(final int[][] data,
			final int start_x, final int end_x,
			final int start_y, final int end_y) {
		// Step 1: Get the sum of the array with index
		// x : start_x -> end_x
		// y : start_y -> end_y
		int sum = 0;
		for (int i = start_y; i <= end_y; i++) {
			// Get the column
			for (int j = start_x; j <= end_x; j++) {
				sum += data[i][j];
			}
		}
		// Step 2: Get the middle value
		int middle = data[(start_y + end_y) / 2][(start_x + end_x) / 2];
		// Step 3: Subtract
		sum = sum - middle;
		return sum;
	}

	// For debug 
	private static int getMiddle(final int[][] data,
			final int start_x, final int end_x,
			final int start_y, final int end_y) {
		return data[(start_y + end_y) / 2][(start_x + end_x) / 2];
	}
}
